home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / gfx / show / jpegAGAsrc21.lha / jpegAGAsrc / ppm2AGA / ppm2AGA.c < prev    next >
C/C++ Source or Header  |  1995-01-18  |  7KB  |  288 lines

  1. /* ppm2AGA main module                */
  2. /* written 1993-95 by Günther Röhrich */
  3. /* This is version 1.6                */
  4.  
  5. #include <clib/exec_protos.h>
  6. #include <clib/intuition_protos.h>
  7. #include <clib/graphics_protos.h>
  8. #include <intuition/intuitionbase.h>
  9. #include <graphics/gfxbase.h>
  10. #include <libraries/iffparse.h>
  11. #include <iffp/ilbmapp.h>
  12. #include <dos/dos.h>
  13. #include <stdio.h>
  14. #include <stdarg.h>
  15. #include <string.h>
  16.  
  17. #ifndef __GNUC__
  18. #include <pragmas/intuition_pragmas.h>
  19. #include <pragmas/graphics_pragmas.h>
  20. #include <pragmas/exec_pragmas.h>
  21. #endif
  22.  
  23. #include "ppm2AGA.h"
  24.  
  25. #ifdef __GNUC__
  26. #include <signal.h>
  27. #define MYSTRCMP strcasecmp
  28. #define MYSTRNCMP strncasecmp
  29. #else
  30. #define MYSTRCMP strcmp
  31. #define MYSTRNCMP strncmp
  32. #endif
  33.  
  34.  
  35. /* externals used by this module */
  36.  
  37. extern int ppm2ilbm(char *PPMfile, ULONG Mode, int NumPlanes, ULONG MaxMem); 
  38. #ifdef AZTEC_C
  39. extern int Enable_Abort; /* Needed to disable default CTRL-C handling */
  40. #endif
  41.  
  42. /* globals defined in this module */
  43.  
  44. char  *ver = "\0$VER: ppm2AGA 1.6 (8.1.95)";
  45. struct Library *IntuitionBase = NULL;
  46. struct Library *GfxBase = NULL;
  47. struct Library *IFFParseBase = NULL;
  48. int floyd=0; /* indicates if FS-dithering should be used */
  49. char *ILBMfile;
  50. char *BaseName=NULL;
  51. int ExactColor=0; /* indicates if shifting colors is allowed */
  52. int GfxEnable=0;  /* indicate if Gfx is enabled */
  53. int VGAenable=0;  /* indicate VGA-mode */
  54. int jpegAGA=0;    /* indicate that map-file should be created */
  55. ULONG SMR=0;      /* indicate that user has chosen a screenmode */
  56. ULONG SMR_DisplayID;  /* this variable contains later the DisplayID */
  57. ULONG SMR_NumPlanes;
  58. ULONG SMR_HAM; 
  59.  
  60. void PLError(char *ErrorString); /* prints the message, cleans up and quits */
  61. void PLExit(int returnvalue); /* cleans up and quits */
  62. void pm_message(char* format, ... );
  63. int AbortCheck(void);
  64. void PLProgress(ULONG Value, ULONG MaxValue);
  65.  
  66.  
  67. #ifdef __GNUC__
  68. int GCCabort=0;
  69. /* this is called when CTRL-C occurs */
  70. void GCCAbortHandler(void)
  71. {
  72.   GCCabort=1;
  73. }
  74. #endif
  75.  
  76. void PLUsage(void)
  77. {
  78.  PLError("Usage: ppm2AGA infile outfile [switches]\n"
  79.          "switches: -HAM8     use HAM8-conversion (default)\n"
  80.          "          -HAM6     use HAM6-conversion\n"
  81.          "          -CMAPn    use COLORMAP conversion with n bitplanes\n"
  82.          "          -E        use exact colors (only COLORMAP mode)\n"
  83.          "          -FS       enable Floyd-Steinberg dithering\n"
  84.          "          -Mx       load pictures up to size x into memory\n"
  85.          "          -2        enable 2-pass processing for HAM mode\n" 
  86.          "          -D        display picture during processing\n"
  87.          "          -VGA      use VGA screenmode\n"
  88.          "          -SMR      use screen mode requester\n"
  89.          "          -jpegAGA  create colormap file for jpegAGA/PhotoCDAGA\n"
  90.          "          -b name   base name for PhotoCDAGA map files\n");
  91. }
  92.  
  93.  
  94. main(int argc, char *argv[])
  95. {
  96.  int Error;
  97.  int i;
  98.  ULONG Mode=HAM8;
  99.  int NumPlanes = 63;
  100.  int Pass = 1; /* 2-pass disabled by default */
  101.  ULONG MaxMem = 1000000;
  102.  
  103.  #ifdef AZTEC_C             /* Disable Aztec C CTRL-C handling */
  104.  Enable_Abort = 0;
  105.  #endif
  106.  #ifdef __GNUC__            /* Modify GNU C CTRL-C handling */
  107.  signal(SIGINT, GCCAbortHandler);
  108.  #endif
  109.  
  110.  puts("ppm2AGA V1.6 written by Günther Röhrich.");
  111.  
  112.  /* remove the comments for beta versions */
  113.  /*  puts("Preliminary version. DO NOT SPREAD IT!");  */
  114.  
  115.  
  116.  /* Open all the libraries we need */
  117.  
  118.  if(!(IntuitionBase = OpenLibrary((UBYTE *)"intuition.library", 33)))
  119.    PLError("Can't open intuition.library V33 or higher.\n");
  120.  
  121.  if(!(GfxBase = OpenLibrary((UBYTE *)"graphics.library",33)))
  122.    PLError("Can't open graphics.library V33 or higher.\n");
  123.  
  124.  /* iffparse.library V37 works also with Kickstart 1.2/1.3 */
  125.  
  126.  if(!(IFFParseBase = OpenLibrary((UBYTE *)"iffparse.library",36)))
  127.    PLError("Can't open iffparse.library V36 or higher.\n");
  128.  
  129.  if(argc < 3) PLUsage();
  130.  
  131.  for(i=3; i<argc; i++)
  132.  {
  133.    #ifndef __GNUC__
  134.    strupr(argv[i]);
  135.    #endif
  136.    if(!MYSTRNCMP(argv[i], "-HAM8", 5))
  137.    {
  138.      Mode = HAM8;
  139.      NumPlanes = 63;
  140.    }
  141.    else if(!MYSTRNCMP(argv[i], "-HAM6", 5))
  142.    {
  143.      Mode = HAM6;
  144.      NumPlanes = 15;
  145.    }
  146.    else if(!MYSTRNCMP(argv[i], "-CMAP", 5))
  147.    {
  148.      Mode = COLORMAP;
  149.      NumPlanes = (int)strtoul(&argv[i][5], NULL, 0);
  150.      if(NumPlanes < 1 || NumPlanes > 8)
  151.      PLError("Only 1 to 8 planes allowed.\n");
  152.    }
  153.    else if(!MYSTRNCMP(argv[i], "-M", 2))
  154.    {
  155.      MaxMem = strtoul(&argv[i][2], NULL, 0);
  156.    }
  157.    else if(!MYSTRNCMP(argv[i], "-FS", 3))
  158.    {
  159.      floyd = 1;
  160.    }
  161.    else if(!MYSTRNCMP(argv[i], "-E", 2))
  162.    {
  163.      ExactColor = 1;
  164.    }
  165.    else if(!MYSTRNCMP(argv[i], "-D", 2))
  166.    {
  167.      GfxEnable = 1;
  168.    }
  169.    else if(!MYSTRNCMP(argv[i], "-2", 2))
  170.    {
  171.      Pass = 0;
  172.    }
  173.    else if(!MYSTRNCMP(argv[i], "-VGA", 4))
  174.    {
  175.      VGAenable = 1;
  176.    }
  177.  
  178.    else if(!MYSTRNCMP(argv[i], "-SMR", 4))
  179.    {
  180.      SMR = 1;
  181.    }
  182.  
  183.    else if(!MYSTRNCMP(argv[i], "-jpegAGA", 8))
  184.    {
  185.      jpegAGA = 1;
  186.    }
  187.  
  188.    else if(!MYSTRNCMP(argv[i], "-b", 2))
  189.    {
  190.      if(argc == i+1) PLUsage(); /* last argument */
  191.      BaseName = argv[i+1];
  192.      i++;
  193.    }
  194.    else PLUsage();
  195.    if( (jpegAGA == 1) && (Pass == 0 || Mode != HAM8)) PLUsage(); 
  196.  }    
  197.  
  198.  
  199.  if(SMR)
  200.  {
  201.    if(ChooseScreenMode()) PLError("No screen mode selected.\n");
  202.    if(SMR_HAM)
  203.    {
  204.      if(SMR_NumPlanes == 8)
  205.      {
  206.        Mode = HAM8;
  207.        NumPlanes = 63;
  208.      }
  209.      else
  210.      {
  211.        Mode = HAM6;
  212.        NumPlanes = 15;
  213.      }
  214.    }
  215.    else
  216.    {
  217.      Mode = COLORMAP;
  218.      NumPlanes = SMR_NumPlanes;
  219.    } 
  220.  }
  221.  
  222.  ILBMfile = argv[2];
  223.  if(Mode == HAM8 || Mode == HAM6) NumPlanes = NumPlanes + Pass;
  224.  
  225.  Error = ppm2ilbm(argv[1], Mode, NumPlanes, MaxMem);
  226.  
  227.  /* if(Error) pm_message("Error, no picture created.\n"); */
  228.  
  229.  PLExit(Error);  
  230. }
  231.  
  232. void PLError(char *ErrorString)
  233. {
  234.  pm_message(ErrorString);
  235.  PLExit(10);
  236. }
  237.  
  238.  
  239.  
  240.  
  241. /* NOTE: if you want to implement a GUI you only have to */
  242. /* change the functions below, not the complete program  */
  243.  
  244.  
  245. /* this is called on exit */
  246.  
  247. void PLExit(int returnvalue)
  248. {
  249.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  250.  if(GfxBase)       CloseLibrary(GfxBase);
  251.  if(IFFParseBase)  CloseLibrary(IFFParseBase);
  252.  exit(returnvalue);
  253. }
  254.  
  255.  
  256. /* this is called to see if we must abort */
  257.  
  258. int AbortCheck(void)
  259. {
  260.  #ifndef __GNUC__
  261.  return SetSignal(0L,0L)&SIGBREAKF_CTRL_C;
  262.  #else
  263.  return GCCabort;
  264.  #endif 
  265. }
  266.  
  267.  
  268. /* this is called for progress reports */
  269. /* not called in this version */
  270.  
  271. void PLProgress(ULONG Value, ULONG MaxValue)
  272. {
  273.  /* we do nothing special right now */
  274.  printf("\015Progress: %5.2f%%", Value * 100.0 / (MaxValue + 1));
  275. }
  276.  
  277.  
  278. /* this is called when a message must be printed */
  279.  
  280. void pm_message(char* format, ... )
  281. {
  282.   va_list args;
  283.  
  284.   va_start( args, format );
  285.   vprintf(format, args );
  286.   va_end( args );
  287. }
  288.